
Imports std
Imports System.IO
Imports common

Public Module main

    Public Sub Main(ByVal args() As String)
        On Error Resume Next
        debugpause()

        If args.Length < 2 Then
            raiseError("arguments count error, htmlkick [<kickmethod>] <input> <output>. " _
                        + "kickmethod, kickRemark / kickScript / kickStyle / kickTags / kickAll, default kickAll. " _
                        + "if input or output is /-, use console.", errorHandle.errorType.user)
        Else
            Dim reader As TextReader = Nothing
            Dim writer As TextWriter = Nothing
            assert(initialInput(args(args.Length() - 2), reader) _
                    , "cannot open file for input, " + args(args.Length() - 2))
            assert(initialOutput(args(args.Length() - 1), writer) _
                    , "cannot open file for output, " + args(args.Length() - 1))
            Dim content As String = Nothing
            Dim input As String = Nothing
            input = reader.ReadLine
            While Not input Is Nothing
                content += input + newline.incode
                input = reader.ReadLine
            End While
            closestream(reader)

            If args.Length = 2 OrElse strsame(args(0), "kickall", False) Then
                htmlUtils.kickAll(content)
            ElseIf strsame(args(0), "kickscript", False) Then
                htmlUtils.kickScript(content)
            ElseIf strsame(args(0), "kickstyle", False) Then
                htmlUtils.kickStyle(content)
            ElseIf strsame(args(0), "kicktags", False) Then
                htmlUtils.kickTags(content)
            ElseIf strsame(args(0), "kickremark", False) Then
                htmlUtils.kickRemark(content)
            Else
                htmlUtils.kickAll(content)
            End If
            writer.Write(content)
            closestream(writer)
        End If
    End Sub

End Module
